package com.shaoshaohuo.app.adapter;

import java.util.List;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.Evaluation;
import com.shaoshaohuo.app.utils.ImageLoadUtil;
import com.shaoshaohuo.app.utils.StringHelper;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

/**
 * 我的评价页面 adapter
 *
 * @param <T>
 */
public class EvaluationListAdapter<T> extends MyBaseAdapter<Evaluation> {

    public EvaluationListAdapter(Context ctx, List<Evaluation> list, boolean flag) {
        super(ctx, list, flag);
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup group) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.view_evaluation_list_item, null);
            holder = new ViewHolder();
            holder.titleText = (TextView) convertView.findViewById(R.id.textview_name);
            holder.timeText = (TextView) convertView.findViewById(R.id.textview_time);
            holder.contentText = (TextView) convertView.findViewById(R.id.textview_content);
            holder.ratingBar = (RatingBar) convertView.findViewById(R.id.ratingbar);
            holder.iv_head = (ImageView) convertView.findViewById(R.id.iv_head);
            holder.tv_weight = (TextView) convertView.findViewById(R.id.tv_weight);
            holder.tv_buy_date = (TextView) convertView.findViewById(R.id.tv_buy_date);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Evaluation msg = list.get(pos);

        holder.titleText.setText(msg.getRealname());
        holder.timeText.setText(StringHelper.formatDateMinute(msg.getCursor()));
        holder.contentText.setText(msg.getContent());
        holder.ratingBar.setRating(Float.parseFloat(msg.getStartnum()));
        ImageLoader.getInstance().displayImage(msg.getAvatar(), holder.iv_head,
                ImageLoadUtil.getDisplayImageOptions(R.drawable.icon_head_eva_ad, 180));
        holder.tv_weight.setText("购买量:"+ StringHelper.formatDateDay(msg.getGoodsquantity()));
        holder.tv_buy_date.setText("购买时间:"+msg.getGoodscreatedate());
        return convertView;
    }

    static class ViewHolder {
        TextView titleText;
        TextView timeText;
        TextView contentText;
        RatingBar ratingBar;
        ImageView iv_head;
        TextView tv_weight;
        TextView tv_buy_date;
    }

}
